﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<meta content="" name="description" />
    <meta content="webthemez" name="author" />
    <title>一起吧 &mdash; 后台管理</title>
    <!-- Bootstrap Styles-->
    <link href="css/bootstrap.css"  rel="stylesheet" />
    <!-- Eeasy UI Styles-->
    <link href="easyui/default/easyui.css" rel="stylesheet"/>
    <!-- Eeasy UI Icon -->
    <link href="easyui/icon.css"/>
    <!-- FontAwesome Styles-->
    <link href="css/font-awesome.css" rel="stylesheet" />
    <!-- Morris Chart Styles-->
    <link href="js/morris/morris-0.4.3.min.css" rel="stylesheet" />
    <!-- Custom Styles-->
    <link href="css/custom-styles.css" rel="stylesheet" />
    <!-- Google Fonts-->
    <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
    <link rel="stylesheet" href="js/Lightweight-Chart/cssCharts.css"/>
    <style rel="stylesheet">
        .datagrid-cell-c1-picture>div{
            left: 43%;
        }
        /*禁用滚动条*/
        body{
            overflow: hidden;
        }
    </style>
</head>

<body>
    <div id="wrapper">
        <nav class="navbar navbar-default top-navbar" role="navigation">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".sidebar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="/front/index.html"><img src="/front/images/logo.png"/></a>

                <div id="sideNav" href="">
                    <i class="fa fa-bars icon"></i>
                </div>
            </div>

            <ul class="nav navbar-top-links navbar-right">
                <li class="dropdown">
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#" aria-expanded="false">
                        <i class="fa fa-envelope fa-fw"></i> <i class="fa fa-caret-down"></i>
                    </a>
                    <ul class="dropdown-menu dropdown-messages">
                        <li>
                            <a href="#">
                                <div>
                                    <strong>John Doe</strong>
                                    <span class="pull-right text-muted">
                                        <em>Today</em>
                                    </span>
                                </div>
                                <div>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s...</div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="#">
                                <div>
                                    <strong>John Smith</strong>
                                    <span class="pull-right text-muted">
                                        <em>Yesterday</em>
                                    </span>
                                </div>
                                <div>Lorem Ipsum has been the industry's standard dummy text ever since an kwilnw...</div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="#">
                                <div>
                                    <strong>John Smith</strong>
                                    <span class="pull-right text-muted">
                                        <em>Yesterday</em>
                                    </span>
                                </div>
                                <div>Lorem Ipsum has been the industry's standard dummy text ever since the...</div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a class="text-center" href="#">
                                <strong>Read All Messages</strong>
                                <i class="fa fa-angle-right"></i>
                            </a>
                        </li>
                    </ul>
                    <!-- /.dropdown-messages -->
                </li>
                <!-- /.dropdown -->
                <li class="dropdown">
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#" aria-expanded="false">
                        <i class="fa fa-tasks fa-fw"></i> <i class="fa fa-caret-down"></i>
                    </a>
                    <ul class="dropdown-menu dropdown-tasks">
                        <li>
                            <a href="#">
                                <div>
                                    <p>
                                        <strong>Task 1</strong>
                                        <span class="pull-right text-muted">60% Complete</span>
                                    </p>
                                    <div class="progress progress-striped active">
                                        <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 60%">
                                            <span class="sr-only">60% Complete (success)</span>
                                        </div>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="#">
                                <div>
                                    <p>
                                        <strong>Task 2</strong>
                                        <span class="pull-right text-muted">28% Complete</span>
                                    </p>
                                    <div class="progress progress-striped active">
                                        <div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="28" aria-valuemin="0" aria-valuemax="100" style="width: 28%">
                                            <span class="sr-only">28% Complete</span>
                                        </div>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="#">
                                <div>
                                    <p>
                                        <strong>Task 3</strong>
                                        <span class="pull-right text-muted">60% Complete</span>
                                    </p>
                                    <div class="progress progress-striped active">
                                        <div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 60%">
                                            <span class="sr-only">60% Complete (warning)</span>
                                        </div>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="#">
                                <div>
                                    <p>
                                        <strong>Task 4</strong>
                                        <span class="pull-right text-muted">85% Complete</span>
                                    </p>
                                    <div class="progress progress-striped active">
                                        <div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="85" aria-valuemin="0" aria-valuemax="100" style="width: 85%">
                                            <span class="sr-only">85% Complete (danger)</span>
                                        </div>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a class="text-center" href="#">
                                <strong>See All Tasks</strong>
                                <i class="fa fa-angle-right"></i>
                            </a>
                        </li>
                    </ul>
                    <!-- /.dropdown-tasks -->
                </li>
                <!-- /.dropdown -->
                <li class="dropdown">
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#" aria-expanded="false">
                        <i class="fa fa-bell fa-fw"></i> <i class="fa fa-caret-down"></i>
                    </a>
                    <ul class="dropdown-menu dropdown-alerts">
                        <li>
                            <a href="#">
                                <div>
                                    <i class="fa fa-comment fa-fw"></i> New Comment
                                    <span class="pull-right text-muted small">4 min</span>
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="#">
                                <div>
                                    <i class="fa fa-twitter fa-fw"></i> 3 New Followers
                                    <span class="pull-right text-muted small">12 min</span>
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="#">
                                <div>
                                    <i class="fa fa-envelope fa-fw"></i> Message Sent
                                    <span class="pull-right text-muted small">4 min</span>
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="#">
                                <div>
                                    <i class="fa fa-tasks fa-fw"></i> New Task
                                    <span class="pull-right text-muted small">4 min</span>
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="#">
                                <div>
                                    <i class="fa fa-upload fa-fw"></i> Server Rebooted
                                    <span class="pull-right text-muted small">4 min</span>
                                </div>
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a class="text-center" href="#">
                                <strong>See All Alerts</strong>
                                <i class="fa fa-angle-right"></i>
                            </a>
                        </li>
                    </ul>
                    <!-- /.dropdown-alerts -->
                </li>
                <!-- /.dropdown -->
                <li class="dropdown">
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#" aria-expanded="false">
                        <i class="fa fa-user fa-fw"></i> <i class="fa fa-caret-down"></i>
                    </a>
                    <ul class="dropdown-menu dropdown-user">
                        <li><a href="#"><i class="fa fa-user fa-fw"></i> User Profile</a>
                        </li>
                        <li><a href="#"><i class="fa fa-gear fa-fw"></i> Settings</a>
                        </li>
                        <li class="divider"></li>
                        <li><a href="#"><i class="fa fa-sign-out fa-fw"></i> Logout</a>
                        </li>
                    </ul>
                    <!-- /.dropdown-user -->
                </li>
                <!-- /.dropdown -->
            </ul>
        </nav>
        <!--/. NAV TOP  -->
        <nav class="navbar-default navbar-side" role="navigation">
            <div class="sidebar-collapse">
                <ul class="nav" id="main-menu">

                    <li>
                        <a href="enterprise.html"><i class="fa fa-dashboard"></i>公司信息管理</a>
                    </li>
                    <li>
                        <a href="message.html"><i class="fa fa-desktop"></i>留言管理</a>
                    </li>
                    <li>
                        <a href="carousel.html"><i class="fa fa-desktop"></i>轮播图管理</a>
                    </li>
                    <li>
                        <a href="specialty.html"><i class="fa fa-desktop"></i>优势管理</a>
                    </li>

                    <li>
                        <a href="statistics.html"><i class="fa fa-sitemap"></i>统计管理</span></a>
                    </li>

                    <li>
                        <a href="service.html"><i class="fa fa-qrcode"></i>服务管理</a>
                    </li>

                    <li>
                        <a href="staff.html"><i class="fa fa-table"></i> 团队管理</a>
                    </li>
                    <li>
                        <a href="news.html"><i class="fa fa-edit"></i>新闻管理</a>
                    </li>
                    <li>
                        <a class="active-menu" href="dynamic.html"><i class="fa fa-sitemap"></i>资讯管理</a>
                    </li>
                    <li>
                        <a href="product.html"><i class="fa fa-fw fa-file"></i>软件管理</a>
                    </li>
                    <li>
                        <a href="activity.html"><i class="fa fa-fw fa-file"></i>活动管理</a>
                    </li>
                </ul>

            </div>

        </nav>
        <!-- /. NAV SIDE  -->
      
		<div id="page-wrapper">
            <div id="page-inner">
               <!-- table start-->
                <div id="tb-toolbar">
                    <a href="#" class="easyui-linkbutton" onclick="addrow()" data-options="plain:true">新增</a>
                    <a href="#" class="easyui-linkbutton" onclick="deleterow()" data-options="plain:true">删除</a>
                </div>
                <table  id="admintable">

                </table>
                <!-- table end-->
			<div class="copyrights">Collect from <a href="http://www.cssmoban.com/" >企业网站模板</a></div>
				<footer><p>Copyright &copy; 2016.Company name All rights reserved.<a target="_blank" href="http://www.cssmoban.com/">&#x7F51;&#x9875;&#x6A21;&#x677F;</a></p>

				</footer>
            </div>
            <!-- /. PAGE INNER  -->
        </div>
        <!-- /. PAGE WRAPPER  -->
    </div>
    <!-- /. WRAPPER  -->
    <!-- JS Scripts-->
    <!-- jQuery Js -->
    <script src="js/jquery-1.10.2.js"></script>
    <!-- Bootstrap Js -->
    <script src="js/bootstrap.min.js"></script>
    <!-- Eeasy UI Js -->
    <script src="easyui/jquery.easyui.min.js"></script>
    <script src="easyui/locale/easyui-lang-zh_CN.js"></script>
    <!-- Metis Menu Js -->
    <script src="js/jquery.metisMenu.js"></script>
    <!-- Custom Js -->
    <script src="js/jquery.ocupload-1.1.2.js"></script>
    <script type="text/javascript">
        //记录当前行数据
        var rowData=null;
        //初始化一键上传
        var initUpload=false;
        $(function() {
            $('#admintable').datagrid({
                toolbar: '#tb-toolbar',//数据网格（datagrid）面板的头部工具栏
                striped:true,//奇偶行使用不同背景色
                nowrap:true,//把数据显示在一行里
                method:'post',//请求远程数据的方法（method）类型
                width: '100%',
                fitColumns:true,//自动扩大或缩小列的尺寸以适应网格的宽度并且防止水平滚动
                idField: 'id',//指示哪个字段是标识字段
                pagination:true,//分页
                pageNumber:1,//初始化页码
                pageSize:10,//初始化页面尺寸
                pageList:[10],//页面尺寸数组
                checkOnSelect:true,//checkOnSelect
                url: '/back/queryAllDynamicByPage',
                queryParams:{},//当请求远程数据时，发送的额外参数
                columns: [
                    [{
                        field:'checkbox',
                        checkbox:true,
                        align:'center'
                    },
                        {
                            field: 'id',
                            title: 'ID',
                            align: 'center',
                            width: 60
                        },
                        {
                            field: 'title',
                            title: '标题',
                            align: 'center',
                            width: 100,
                            editor: 'text'
                        },
                        {
                            field: 'category',
                            title: '类型',
                            width: 80,
                            align: 'center',
                            editor: 'text'
                        },
                        {
                            field: 'description',
                            title: '描述',
                            width: 120,
                            align: 'center',
                            editor: 'text'
                        },
                        {
                            field: 'dynDate',
                            title: '日期',
                            width: 120,
                            align: 'center',
                            editor: 'datebox'
                        },
                        {
                            field: 'action',
                            title: '操作',
                            width: 100,
                            align: 'center',
                            formatter: function(value, row, index) {
                                if (row.editing) {
                                    var s = '<a href="#" onclick="saverow(this)">保存</a> ';
                                    var c = '<a href="#" onclick="cancelrow(this)">取消</a>';
                                    return s + c;
                                } else {
                                    var e = '<a href="#" onclick="editrow(this)">编辑</a> ';
                                    var d = '<a href="#" onclick="deleterow(this)">删除</a>';
                                    return e + d;
                                }
                            }
                        }]],
                onBeforeEdit: function(index, row) {
                    row.editing = true;
                    rowData=row;
                    updateActions(index);
                },
                onAfterEdit: function(index, row) {
                    row.editing = false;
                    rowData.editing=false;
                    updateActions(index);
                },
                onCancelEdit: function(index, row) {
                    row.editing = false;
                    rowData.editing=false;
                    updateActions(index);
                },
                onClickRow: function (rowIndex,row) {
                    rowData=row;
                },
            });
        });
        function updateActions(index) {
            $('#admintable').datagrid('refreshRow',index);
            $('#admintable').datagrid('updateRow', {
                index: index,
                row: rowData
            });
        }
        function getRowIndex(target) {
            var tr = $(target).closest('tr.datagrid-row');
            return parseInt(tr.attr('datagrid-row-index'));
        }
        function addrow(){
            rowData={editing:true};
            $('#admintable').datagrid('insertRow',{
                index: 0,
                row: rowData
            })
            $('#admintable').datagrid('beginEdit',0);
        }
        function editrow(target) {
            $('#admintable').datagrid('beginEdit', getRowIndex(target));
        }
        function deleterow(target) {
            if(target){
                var index=getRowIndex(target);
                var currentRow=getRow(index);
            }else{
                //获取选择的行
                var rows=$('#admintable').datagrid('getSelections');
                if(rows.length<1){
                    $.messager.alert('系统提示','至少选择一行','warning');
                    return ;
                }
            }
            $.messager.confirm('系统提示', '确定删除吗?',
                function(r) {
                    if (r) {
                        var ids=new Array();
                        //遍历选择的行
                        if(target){
                            ids.push(currentRow.id);
                        }else{
                            for(var i=0;i<rows.length;i++){
                                ids.push(rows[i].id);
                            }
                        }
                        //后台删除
                        var flag=sendAjax({
                            url: '/back/deleteEnterprise',
                            data:{'ids':ids},
                            successText: '删除成功',
                            errorText: '删除失败'
                        })
                        if(flag){
                            //遍历选中行删除或者删除指定行
                            if(target){
                                $('#admintable').datagrid('deleteRow', getRowIndex(target));
                            }else{
                                for(var i=0;i<rows.length;i++){
                                    var cru_index=$('#admintable').datagrid('getRowIndex', rows[i]);
                                    $('#admintable').datagrid('deleteRow', cru_index);
                                }
                            }
                        }else{
                            rowData.editing=false;
                            updateActions(getRowIndex(target));
                        }
                    }
                });
        }
        function saverow(target) {
            var url='/back/addDynamic';
            var rowIndex=getRowIndex(target);
            $('#admintable').datagrid('endEdit', rowIndex);
            var data=getRow(rowIndex);
            var newRow=data;
            rowData=data;
            if(rowData.id){
                //更新
                url= '/back/updateDynamic';
            }else {
                //添加
                url: '/back/addDynamic';
            }
            $.ajax({
                url: url,
                type: 'post',
                data: data
            }).done(function(json){
                if(json){
                    newRow=json;
                    $('#admintable').datagrid('updateRow', {
                        index: rowIndex,
                        row: JSON.parse(newRow)
                    });
                    $.messager.alert('系统消息','保存成功','info');
                }else{
                    rowData.editing=true;
                    updateActions(rowIndex);
                    $.messager.alert('系统消息','保存失败','error');
                }
                $('#admintable').datagrid('updateRow',{
                    index: rowIndex,
                    row: newRow
                })
            }).fail(function(){
                rowData.editing=true;
                updateActions(rowIndex);
                $.messager.alert('系统消息','服务器正忙，请稍后再试...','error');
            })
        }

        function cancelrow(target) {
            $('#admintable').datagrid('cancelEdit', getRowIndex(target));
        }
        //获取指定索引的行
        function getRow(index){
            var rows=$('#admintable').datagrid('getRows');
            for(var i=0;i<rows.length;i++){
                var row=rows[i];
                var rowIndex=$('#admintable').datagrid('getRowIndex',row);
                if(rowIndex==index){
                    return row;
                }
            }
        }
        //显示图片
        function showPic(target,value){
            if(!initUpload){
                uploadPic();
                initUpload=true;
            }
            if($(target).children('img')){
                var img='<img src="/upload/'+value+'" style="width:50px;height:50px;position: absolute;z-index: 999;"/>';
                $(target).append(img);
            }else {
                $(target).children('img').show();
            }
        }
        //隐藏图片
        function hidePic(target){
            $(target).children('img').hide();
        }

        function uploadPic(){
            var i=$('a.upload-pic');
            $('a.upload-pic').upload({
                action: '/back/dynamicUpload',
                name:'file',
                // params:{'carId':accidentCarId,'time':accidentTime},
                onComplete:function(data){
                    if(data&&data!="error"){
                        rowData.picture=data;
                        alert('success');
                    }else{
                        alert('error');
                    }
                }
            })
        }
        //发送ajax请求
        function sendAjax(obj) {
            $.ajax({
                url: obj.url,
                type: 'post',
                data:obj.data
            }).done(function (msg) {
                if(msg=="error"){
                    $.messager.alert('系统消息',obj.errorText,'error');
                    return false;
                }else if(msg=="ok"){
                    $.messager.alert('系统消息',obj.successText,'error');
                    return true;
                }
            }).fail(function () {
                $.messager.alert('系统消息','服务器正忙，请稍后再试...','error');
                return false;
            })
        }
        $.extend($.fn.datagrid.defaults.editors, {
            text: {
                init: function(container, options){
                    var input = $('<input  type="text" style="text-align: center" class="datagrid-editable-input">').appendTo(container);
                    return input;
                },
                destroy: function(target){
                    $(target).remove();
                },
                getValue: function(target){
                    return $(target).val();
                },
                setValue: function(target, value){
                    $(target).val(value);
                },
                resize: function(target, width){
                    $(target)._outerWidth(width);
                }
            }
        });
    </script>
</body>

</html>